package code.structure.module.task.data
{
	import code.structure.module.configs.data.task.TaskSubConfigData;

	/**
	 * 子任务数据
	 * @author CYoung
	 * 2014-8-4下午10:03:09
	 */
	public class TaskSubData
	{
		/** 子任务ID */
		public var id:int;
		/** 子任务配置数据 */
		public var config:TaskSubConfigData;
		private var _num:int;

		/** 子任务完成数量 */
		public function get num():int { return _num; }
		public function set num(value:int):void {
			_num = value;
			isComplete = (_num >= config.requireNum);
		}

		/** 子任务是否跳过 */
		public var isSkip:Boolean;
		/** 子任务是否完成 */
		public var isComplete:Boolean;
		/** 父任务 */
		public var parent:TaskData;
		
		public function TaskSubData(data:TaskSubConfigData, value:int)
		{
			id = data.id;
			config = data;
			num = value;
			if(value == -1) {
				isSkip = true;
				num = config.requireNum;
			}
		}
		/**
		 * 更改子任务完成数量
		 * @param id 待检测ID
		 * @param count 数量
		 * @param isAdd 添加|赋值
		 */		
		public function addDoNum(id:String, count:int, isAdd:Boolean = true):void
		{
			if(isSkip) return;
			if(config.requireId && config.requireId != id) return;
			isAdd==true? (num += count): num = count;
			isComplete = (num >= config.requireNum);
		}
	}
}